// ITI1120 (Fall 2012), Lab 3, Exercise 2 // Name: , Student #: 1234567 // Program Description: import java.util.Scanner ; class Lab3Ex2V1 { /** * An Activity according to Temperature */ public static void main (String[] args) { // KEYBOARD INPUT CONFIGURATION // You can safely remove these lines if you use // the ITI1120 class for data entry Scanner input = new Scanner(System.in); // VARIABLE DECLARATIONS double temperature; // The current temperature int numActivity; // the number of the activity // PRINT ID INFO System.out.println(); System.out.println("ITI1120 (F-2012), Lab 3, Exercise 2"); System.out.println("Name: John Doe, Student #: 1234567"); System.out.println("TA: YourTA"); System.out.println(); // READ INPUT System.out.print("What is the temperature: "); temperature = input.nextDouble(); // CALL VERIFICATION METHOD numActivity = selectActivity(temperature); // SHOW RESULT if(numActivity == 1) { System.out.println("The recommended activity is swimming"); } else { /* do nothing */ } if(numActivity == 2) { System.out.println("The recommended activity is soccer"); } else { /* do nothing */ } if(numActivity == 3) { System.out.println("The recommended activity is volleyball"); } else { /* do nothing */ } if(numActivity == 4) { System.out.println("The recommended activity is skiing"); } else { /* do nothing */ } } /** * Description: Return the number of the activity * depending on temperature. * Parameters (DATA): temp - the current temperature */ private static int selectActivity(double temp) { // DECLARE RETURN VARIABLE int numAct; // activity type if age is within limits. numAct = 0; //DETERMINE RESULT //Version 1: Sequence of branches if( temp >= 80.0 )//If temp is above 80.0 degrees { numAct = 1; } else { /* do nothing */ } if( temp >= 60.0 && temp < 80.0 ) //if temp is between [60,80) { numAct = 2; } else { /* do nothing */ } if( temp >=40.0 && temp < 60.0 )//if temp is between [40,60) { numAct = 3; } else { /* do nothing */ } if( temp < 40 )//if temp is below 40 degrees { numAct = 4; } else { /* do nothing */ } // RETURN THE RESULT return(numAct); } }